#include "message.hpp"
#include "net.hpp"
#include <thread>
#include <jsoncpp/json/json.h>

void onMessage(const bitrpc::BaseConnection::ptr &conn, bitrpc::BaseMessage::ptr &msg)
{
    std::string body = msg->serialize();
    std::cout << body << std::endl;
}

int main()
{
    auto client = bitrpc::ClientFactory::create("127.0.0.1", 9090);
    client->setMessageCallback(onMessage);
    client->connect();
    auto rpc_req = bitrpc::MessageFactory::create<bitrpc::RpcRequest>();
    rpc_req->setId("11111");
    rpc_req->setMType(bitrpc::MType::REQ_RPC);
    rpc_req->setMethod("Add");
    Json::Value param;
    param["num1"] = 11;
    param["num2"] = 22;
    rpc_req->setParams(param);
    client->send(rpc_req);
    std::this_thread::sleep_for(std::chrono::seconds(10)); // 休眠十秒
    client->shutdown();

    return 0;
}